<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约列表</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="fileNumber" width="300" label="档案号" align="center"></el-table-column>

                <el-table-column prop="name" width="80" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                <el-table-column prop="type" label="预约套餐" align="center"></el-table-column>
                <el-table-column prop="state" width="80" label="预约状态" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.state == '0' ? '未确认' :  scope.row.state == '1' ? '已确认' : '已预约'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="预约日期" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="300" >
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button type="primary" size="mini" @click="handleUpdateReservation(scope.row)">确认预约</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card" >
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataHandleAdd" :model="formData" label-position="right" :rules="rules" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <div class="block">
                                                <el-form-item label="出生日期" prop="birthday">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期"
                                                        value-format="yyyy-MM-dd">
                                                </el-date-picker>
                                                </el-form-item>
                                            </div>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄" prop="age">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="适用性别" prop="sex">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="婚姻状态" prop="marriage">
                                                <el-select v-model="formData.marriage">
                                                    <el-option label="未婚" value="0"></el-option>
                                                    <el-option label="已婚" value="1"></el-option>
                                                    <el-option label="离异" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约套餐" prop="setMeal">
                                                <el-select v-model="options.name"  filterable placeholder="请选择" >
                                                    <el-option
                                                            v-for="item in options"
                                                            :key="item.name"
                                                            :label="item.name"
                                                            :value="item.name">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约状态" prop="state">
                                                <el-select v-model="formData.state">
                                                    <el-option label="未确认" value="0"></el-option>
                                                    <el-option label="已确认" value="1"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <div class="block">
                                                <el-form-item label="预约日期" prop="date">
                                                    <el-date-picker
                                                            v-model="formData.date"
                                                            type="date"
                                                            placeholder="选择日期"
                                                            format="yyyy-MM-dd">
                                                    </el-date-picker>
                                                </el-form-item>
                                            </div>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="档案号" prop="fileNumber">
                                                <el-input v-model="formData.fileNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑预约" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataEditForm" :model="formData" label-position="right" :rules="rules" label-width="100px">

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <div class="block">
                                                <el-form-item label="出生日期" prop="birthday">
                                                    <el-date-picker
                                                            v-model="formData.birthday"
                                                            type="date"
                                                            placeholder="选择日期"
                                                            format="yyyy-MM-dd">
                                                    </el-date-picker>
                                                </el-form-item>
                                            </div>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄" prop="age">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="适用性别" prop="sex">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="婚姻状态" prop="marriage">
                                                <el-select v-model="formData.marriage">
                                                    <el-option label="未婚" value="0"></el-option>
                                                    <el-option label="已婚" value="1"></el-option>
                                                    <el-option label="离异" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约套餐" prop="setMeal">
                                                <el-select v-model="options.name"  filterable placeholder="请选择" >
                                                    <el-option
                                                            v-for="item in options"
                                                            :key="item.name"
                                                            :label="item.name"
                                                            :value="item.name">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约状态" prop="state">
                                                <el-select v-model="formData.state">
                                                    <el-option label="未确认" value="0"></el-option>
                                                    <el-option label="已确认" value="1"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                        <el-col :span="12">
                                            <div class="block">
                                                <el-form-item label="预约日期" prop="date">
                                                    <el-date-picker
                                                            v-model="formData.date"
                                                            type="date"
                                                            placeholder="选择日期"
                                                            format="yyyy-MM-dd">
                                                    </el-date-picker>
                                                </el-form-item>
                                            </div>
                                        </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="档案号" prop="fileNumber">
                                            <el-input v-model="formData.fileNumber"/>
                                        </el-form-item>
                                    </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            value:"",
            autoUpload: true,//自动上传
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            options: [],//下拉列表套餐数据
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//添加表单窗口中检查组列表数据
            ordersettinglistIds: [],//添加表单窗口中检查组复选框对应id
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                name: [{required: true, message: '名字不能为空', trigger: 'blur'}],
                phoneNumber: [{required: true, message: '手机号不能为空', trigger: 'blur'}],
                idCard: [{required: true, message: '身份证号不能为空', trigger: 'blur'}],
                birthday: [{required: true, message: '生日不能为空', trigger: 'blur'}],
                age: [{required: true, message: '年龄不为空', trigger: 'blur'}],
                sex: [{required: true, message: '性别不能为空', trigger: 'blur'}],
                marriage: [{required: true, message: '婚否不为空', trigger: 'blur'}],
                // setMeal: [{required: true, message: '套餐不为空', trigger: 'blur'}],
                state: [{required: true, message: '预约状态不为空', trigger: 'blur'}],
                fileNumber: [{required: true, message: '档案号不为空', trigger: 'blur'}],
                date: [{required: true, message: '预约日期不为空', trigger: 'blur'}],
            },
        },
        created() {
            this.findPage();
        },
        methods: {
            //添加
            handleAdd() {
                this.$refs['dataHandleAdd'].validate((valid) => {
                    if(valid){
                        alert("表单校验通过");
                        axios.post("/ordersettinglist/add.do?name=" + this.options.name, this.formData).then((res) => {
                            if (res.data.flag) {
                                this.$message.success(res.data.message);
                            } else {
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            this.dialogFormVisible = false;
                            this.findPage();
                        })
                    }

                })
            },
            //分页查询
            findPage() {
                //分页查询的参数
                var temple = this.pagination.queryString;
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: (temple != null && temple === "") ? null : temple
                };
                if (param.queryString != null) {
                    param.currentPage = 1
                }
                //异步进行分页查询
                axios.post("/ordersettinglist/findPage.do", param).then((res) => {
                    //将分页查询的结果绑定到页面中
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.activeName = 'first';
                this.options =[];
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                /*this.findAll();*/
                this.dialogFormVisible = true;
                this.findAllType();
            },

            //弹出编辑窗口
            handleUpdate(row) {
                this.resetForm();
                //查询回显数据
                this.findAll();
                this.findAllType();
                axios.get("/ordersettinglist/findById/"+row.id+".do").then((res)=>{
                    if (res.data.flag){
                        this.formData = res.data.data;
                        console.log(res.data.data);
                    }else {
                        this.$message.error(res.message);
                    }
                });
                //修改编辑表单可见性
                this.dialogFormVisible4Edit = true;
            },

            //编辑预约信息
            handleEdit() {
                console.log(this.formData);
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        alert("表单校验通过");
                        axios.post("/ordersettinglist/update.do", this.formData).then((response) => {
                            //判断后台返回的flag值，true表示编辑操作成功，false为编辑操作失败
                            if (response.data.flag) {
                                this.$message({
                                    message: response.data.message,
                                    type: 'success'
                                })
                            } else {
                                this.$message.error(response.data.message);
                            }
                        }).finally(() => {
                            //隐藏编辑窗口
                            this.dialogFormVisible4Edit = false;
                            //调用分页查询方法
                            this.findPage();
                        });
                    }

                })
            },
            //保存数据到预约设置
            handleUpdateReservation(row){
                this.$confirm('此操作将确认预约, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/ordersettinglist/updateReservation.do?date="+row.date).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success',
                            });

                        } else {
                            alert("确认预约失败！");
                            this.$message.error(res.data.message);
                            return false;
                        }
                    }).finally(() => {
                            this.findPage();
                        }
                    );

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            },

            //删除预约设置中该数据
            handleDelete(row) {
                this.$confirm('此操作将删除条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/ordersettinglist/delete.do?id="+row.id+"&date="+row.date).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });

                        } else {
                            alert("删除失败！");
                            this.$message.error(res.data.message);
                            return false;
                        }
                    }).finally(() => {
                            this.findPage();
                        }
                    );

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            },

            findAllType(){
                axios.get("/setmeal/findAll.do").then((res)=>{
                    if (res.data.flag){
                        this.options = res.data.data;

                    }else {
                        this.$message.error(res.data.message);
                    }
                })
            },

            findAll(){
                //查询全部检查项并赋值到检查项列表
                axios.post("/ordersettinglist/findAll.do").then((res)=>{
                    if (res.data.flag){
                        this.tableData = res.data.data;
                    }else {
                        this.$message.error(res.data.message);
                    }
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //使用临时变量存储搜索框中数据
                var queryString = this.pagination.queryString;
                //修改搜索框中的数据为null
                this.pagination.queryString = null;
                //修改分页查询页码为选中页码
                this.pagination.currentPage = currentPage;
                //调用分页查询
                this.findPage();
                //将搜索框中数据重写回搜索框
                this.pagination.queryString = queryString;
            }
        }
    })
</script>
</html>
